package com.ctint.petdida.adaptadores;

import java.util.LinkedList;

import com.ctint.petdida.R;
import com.ctint.petdida.clases.Refugio;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AdapterRefugio extends ArrayAdapter<Refugio>{
	
	LayoutInflater inflater;
	LinkedList<Refugio> linked;

	public AdapterRefugio(Context context, int resource, int textViewResourceId, LinkedList<Refugio> linked) {
		super(context, resource, textViewResourceId, linked);
		this.inflater = LayoutInflater.from(context);
		this.linked = linked;
	}
	
	public View getView(int position, View convertView, ViewGroup parent){
		View row = convertView;
		Refugio currentRefugio = (Refugio)linked.get(position);
		
		if(row == null){
			row = inflater.inflate(R.layout.row_refugio, null);
		}
		
		//SET IMAGE REFUGIO
		ImageView imageR = (ImageView) row.findViewById(R.id.imagen_refugio);	//Imagen Veterinaria
		imageR.setImageBitmap(currentRefugio.getImagen());
		imageR.setScaleType(ImageView.ScaleType.FIT_CENTER);
		
		//SET TEXT NOMBRE REFUGIO
		TextView txtNombre = (TextView)row.findViewById(R.id.txt_nombre_refugio);
		txtNombre.setText(currentRefugio.getNombre());
		
		//SET TEXT DIRECCION REFUGIO
		TextView txtDistancia = (TextView)row.findViewById(R.id.txt_distancia_refugio);
		txtDistancia.setText(currentRefugio.getDistancia());
		
		return row;
	}

}
